package com.jinzhi.jzweb.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.base.CoreServiceImpl;
import com.jinzhi.common.domain.Tree;
import com.jinzhi.common.utils.BuildTree;
import com.jinzhi.jzweb.dao.OrganizationNewsDao;
import com.jinzhi.jzweb.domain.OrganizationNewsDO;
import com.jinzhi.jzweb.domain.OrganizationRolesDO;
import com.jinzhi.jzweb.pojo.ExportStatisticsVo;
import com.jinzhi.jzweb.service.OrganizationNewsService;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * <pre>
 * 机构信息表
 * </pre>
 * <small> 2020-02-24 21:00:11 | lance</small>
 */
@Service
public class OrganizationNewsServiceImpl extends CoreServiceImpl<OrganizationNewsDao, OrganizationNewsDO> implements OrganizationNewsService {

    public List<Map<Object,Object>> selByOrgId(){
        return baseMapper.selByOrgId();
    }

    public Integer selMaxOrgNum(){
        return baseMapper.selMaxOrgNum();
    }

    public Tree<Map> selOrgList(){
        List<Tree<Map>> trees = new ArrayList<Tree<Map>>();
        List<Map<Object, Object>> maps = baseMapper.selOrgList();
        for (int i=0;i<maps.size();i++) {
            Tree<Map> tree = new Tree<Map>();
            tree.setId(String.valueOf(maps.get(i).get("id")));
            tree.setParentId("0");
            tree.setText(String.valueOf(maps.get(i).get("name")));
            Map<String, Object> state = new HashMap<>(16);
            state.put("opened", true);
            state.put("mType", "user");
            tree.setState(state);
            trees.add(tree);
        }
        // 默认顶级菜单为０，根据数据库实际情况调整
        Tree<Map> t = BuildTree.build(trees);
        return t;
    }

    public List<Map<Object,Object>> selCerOrg(String profileId,String name){
        return baseMapper.selCerOrg(profileId,name);
    }

    public List<Map<Object,Object>> selCerOrgAll(String profileId){
        return baseMapper.selCerOrgAll(profileId);
    }

    public List<Long> selOrgProvince(String province){
        return baseMapper.selOrgProvince(province);
    }

    @Override
    public Long selOrgCadreId(Map map){
        return baseMapper.selOrgCadreId(map);
    }

    @Override
    public List<ExportStatisticsVo> selOrgExportStaList(Map map){
        return baseMapper.selOrgExportStaList(map);
    }

    @Override
    public Page<OrganizationNewsDO> findPageList(Map map, int current, int number) {

        Page<OrganizationNewsDO> page = new Page<OrganizationNewsDO>(current, number);

        return page.setRecords(this.baseMapper.findPageList(page,map));
    }

    @Override
    public List<Map> selOrgExportUnit(Map map){
        return baseMapper.selOrgExportUnit(map);
    }


    @Override
    public List<Map> selmechanismList() {
        return baseMapper.selmechanismList();
    }

}
